

    var vm = new Vue({
        el: "#app",
        data: {
            url: "https://autumnfish.cn",
            playUrl: "",
            musicORplayer: "",
            musicList: [],
            musicNameList: [],
        },
        methods: {
            searchMusic: async function() {
                this.musicNameList = [];
                let url = this.url + "/search?keywords=" + this.musicORplayer;
                let res = await axios.get(url);
                let songs = res.data.result.songs;
                let len = songs.length<=10 ? songs.length : 10;
                
                this.musicList = songs;
                for(let i=0;i<len;i++) {
                    this.musicNameList.push(this.condenseName(songs[i].name, 8));
                }
            },
            playMusic: async function(index) {
                let playUrl = "https://music.163.com/song/media/outer/url?id=" + this.musicList[index].id;
                this.playUrl = playUrl;
            },

            condenseName: function(name, index) {
                if(name.length>=index) {
                    name = name.slice(0,index+1) + "...";
                }
                return name;
            }
        },
    })